<template>
  <div class="header">
    <div class="container">
      <div class="container-left">
        <el-icon class="Fold" @click="collapseFun" v-if="collapse == false">
          <Fold />
        </el-icon>
        <el-icon class="Expand" @click="collapseFun" v-else>
          <Expand />
        </el-icon>
        <breadcrumb></breadcrumb>
      </div>
      <!-- 主题色切换 -->
      <div class="container-right">
        <div class="demo-color-block">
          <span class="demonstration">主题色切换</span>
          <el-color-picker v-model="accentColor" @change="changeColor" />
        </div>
        <el-dropdown :hide-on-click="false">
          <div class="avatar el-dropdown-link">
            <el-avatar
              src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
            />
            <div class="userName">
              admin <el-icon class="el-icon--right"><arrow-down /></el-icon>
            </div>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="logOut">退出登录</el-dropdown-item>
              <el-dropdown-item>修改用户信息</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Fold, Expand } from "@element-plus/icons-vue";
import { ref, onMounted, inject, watch, reactive, computed } from "vue";
import { storeToRefs } from "pinia";
import { useUser } from "@/store/modules/userInfo";
import { ArrowDown } from "@element-plus/icons-vue";
import breadcrumb from "@/components/breadcrumb/index.vue";
import { useRouter } from "vue-router";
const router = useRouter();
const userStore = useUser();
const { colorActive } = storeToRefs(userStore);
const accentColor = ref(colorActive);
const props: any = defineProps({
  collapse: {
    type: Boolean, //当前屏幕减去侧边栏的宽度减去传入的宽度
    default: false,
  },
});
const collapse = computed(() => {
  return props.collapse;
});
const emit = defineEmits(["collapseShow"]);
// 修改整体主体色
const changeColor = (color: any) => {
  userStore.changeColor(color);
};
// 导航缩回还是展开
const collapseFun = () => {
  const collapse = props.collapse == false;
  emit("collapseShow", collapse);
};
// 退出登录
const logOut = () => {
  userStore.logOut();
  router.push("/login");
};
</script>

<style lang="scss" scoped>
// Your scoped styles here
.header {
  width: 100%;
  height: 60px;

  // background-color: #fff;
  .container {
    width: 100%;
    height: 55px;
    background-color: $white;
    box-shadow: $header-shadow;
    display: flex;
    align-items: center;
    justify-content: space-between;
    // cursor: pointer;

    .container-left {
      height: 55px;
      display: flex;
      align-items: center;
      overflow: hidden;

      .Fold,
      .Expand {
        font-size: 20px;
        display: inline-block;
        margin-left: 15px;
        cursor: pointer;

        &:hover {
          opacity: 0.8;
          color: var(--el-color-primary);
        }
      }
    }

    .container-right {
      min-width: 300px;
      height: 50px;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .demonstration {
      padding: 0px 10px 0px 10px;
    }

    .demo-color-block {
      margin-right: 10px;
    }

    .avatar {
      height: 55px;
      margin-right: 20px;
      display: flex;
      align-items: center;
      cursor: pointer;
    }

    .userName {
      color: #333;
      font-size: 14px;
      font-weight: bold;
      padding-left: 10px;
      cursor: pointer;
    }
  }
}

.example-showcase .el-dropdown + .el-dropdown {
  margin-left: 15px;
}

.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}

.el-dropdown,
.el-dropdown * {
  outline: none;
}
</style>
